import { getProfileAPI } from "@/api/user";
// 导入静态路由 初始化
import { routes, resetRouter } from "@/router/index";
export default {
  namespaced: true,
  state: {
    // 权限标识
    permission: [],
    // 路由备份
    menuList: [],
  },
  mutations: {
    // 修改权限标识
    setPermission(state, newPermission) {
      state.permission = newPermission;
    },
    // 修改路由规则
    setMenuList(state, asyncRoutes) {
      state.menuList = [...routes, ...asyncRoutes];
    },
    // 清空路由规则
    clearMenuList(state) {
      state.menuList = [];
      resetRouter();
    },
  },
  // 异步方法
  actions: {
    // 获取用户权限列表
    async getUserPermission(store) {
      const res = await getProfileAPI();
      console.log(res, "获取到用户的权限列表");
      store.commit("setPermission", res.data.permissions);
      return res.data.permissions;
    },
  },
  getters: {},
};
